package com.gxa.service.resume.impl;


import com.gxa.common.R.ResponseData;
import com.gxa.mapper.resume.JianLiMapper;
import com.gxa.pojo.Employee;
import com.gxa.pojo.Jianli;
import com.gxa.service.resume.JianLiService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;


@Service
public class JianLiServiceImpl implements JianLiService {

    @Autowired
    private JianLiMapper jianLiMapper;






    /**
     * 分页查询，关键字名字查询
     * @param currentPage
     * @param pageSize
     * @param name
     * @return
     */
    @Override
    public ResponseData selectAll(int currentPage, int pageSize, String name) {
        if (name==null){
            name="";
        }

        /*
        假设每页显示10条
        那么第一页的数据库下标从0开始
            第二页       下标从10开始
            第二页       下标从20开始
         */
        int index = (currentPage - 1) * pageSize;
        int count = jianLiMapper.selectCount(name);
        List<Jianli> jianliList = jianLiMapper.selectAll(name,index,pageSize);
        ResponseData responseData = new ResponseData();
        responseData.setCode(200);
        responseData.setMsg("查询简历成功");
        responseData.setData(jianliList);
        responseData.setTotal(count);
        return responseData;
    }

    /**
     * 查询员工最大id，返回最大id+1
     * @return
     */
    @Override
    public ResponseData selectEmployeeId() {
        ResponseData responseData = new ResponseData();
        int maxId = jianLiMapper.selectEmployeeId()+1;
        responseData.setCode(200);
        responseData.setMsg("查询员工最大id成功");
        responseData.setData(maxId);

        return responseData;
    }

    /*
    不同状态下的简历
     */
    @Override
    public ResponseData selectByStatus(int status) {
        List<Jianli> jianliList=jianLiMapper.selectByStatus(status);
        ResponseData responseData = new ResponseData();
        responseData.setCode(200);
        responseData.setMsg("查询简历该状态下信息数据成功");
        responseData.setData(jianliList);
        return responseData;

    }

    @Override
    public int count(String name) {
        int count = jianLiMapper.selectCount(name);
        return count;
    }

    @Override
    public ResponseData updateByStatus(int id, int status,String shuoMing) {
        int  updateByStatus = jianLiMapper.updateByStatus(id,status,shuoMing);
        ResponseData responseData = new ResponseData();
        responseData.setCode(200);
        responseData.setMsg("更改简历数据成功");
        return responseData;
    }

    @Override
    public ResponseData insertEmployee(Jianli jianli) {
//        Date date = new Date();//此时date为当前的时间
//        System.out.println(date);
//        SimpleDateFormat dateFormat = new SimpleDateFormat("YYYY-MM-dd");
//        String format = dateFormat.format(date);
//        System.out.println(format+"===================");
//        jianLiMapper.updateStatus(format,(int)jianli.getId());
        Employee employee = new Employee();
        Jianli jianliById = jianLiMapper.selectById((int) jianli.getId());
        /*
        前端传入的值
         */
        employee.setId(jianli.getJianliEmployee().getMaxId());
        employee.setDeptId(jianli.getJianliEmployee().getDeptId());
        employee.setZhiCheng(jianli.getJianliEmployee().getZhiCheng());
        employee.setZhiWu(jianli.getJianliEmployee().getZhiWu());
        employee.setEntryDate(jianli.getJianliEmployee().getEntryDate());
        /*
        后端查询的值
         */
        employee.setBirthday(jianliById.getBirthday());
        employee.setPhone(jianliById.getPhone());
        employee.setSex(jianliById.getSex());
        employee.setEname(jianliById.getName());
        employee.setEducated(jianliById.getEducated());
        employee.setMinZu(jianliById.getMinZu());
        employee.setJiGuan(jianliById.getJiGuan());
        employee.setIdentityCardNumber(jianliById.getIdentityCardNumber());
        employee.setCurrentAddress(jianliById.getCity());
        employee.setHeight(jianliById.getHeight());
        employee.setWeight(jianliById.getWeight());
        employee.setPoliticalFace(jianliById.getPoliticalFace());
        employee.setQq(jianliById.getQq());
        employee.setEmail(jianliById.getEmail());
        employee.setJiNeng(jianliById.getJiNeng());
        employee.setWorkExperience(jianliById.getWorkExperience());
        employee.setPeopleNote(jianliById.getPeopleNote());
        employee.setPeoplePhoto(jianliById.getPeoplePhoto());
        employee.setEntryFormPhoto(jianliById.getEntryFormPhoto());
        employee.setIdentityCardPhoto(jianliById.getIdentityCardPhoto());
//        employee.setEntryDate(jianliById.getEntryDate());

        int insertEmployee=jianLiMapper.insertEmployee(employee);

        ResponseData responseData = new ResponseData();
        responseData.setCode(200);
        responseData.setMsg("插入员工数据成功");
        return responseData;
    }

}
